<?php 
$this->categories['0'] = "None";
$cur_page=$this->posts->getCurrentPageNumber();
$per_page=$this->posts->getItemCountPerPage();
$count =(($cur_page-1) * $per_page)+1;
 ?>
<div class="breadLine">
	<ul class="breadcrumb">
		<li><a href="#">Simple Admin</a> <span class="divider">&gt;</span></li>                
		<li class="active">Tables</li>
	</ul>
</div>
<div class="workplace">
<div class="table-sorting">
<table width=100% class="table ">
	<thead>
	<tr>
	<th>#</th>
	<th width=380>Title</th>
	<th>Category</th>
	<th>Created</th>
	<th width=100>Author</th>
	<th>Act</th>
	</tr>
	</thead>
	<form action="<?php echo $this->adminURL('post', 'list') ?>" method="get" id="frmSearch">
	<tr class="search">
	<td>&nbsp;</td>
	<td>
		<input type="text" placeholder="Tiêu đề" name="q" value="<?php echo $this->q ; ?>"/>
	</td>
	<td>
<select name="cate" id="cate">
<?php foreach ($this->categories as $k=>$v) {
	echo "<option value=\"$k\"";
	if ($this->c == $k)
		echo " selected=selected ";
	echo ">".$v."</option>";
} ?>
</select>
	</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</tr>
	</form>
	<?php 
if($this->posts) foreach ($this->posts as $post){ ?>

<tr>
	<td><?php echo $count++; ?></td>
	<td><?php echo $post['title'];?></td>
	<td><?php echo $this->categories[$post['category_id']];?></td>
	<td><?php echo date('d/m/Y H:i:s', $post['created']);?></td>
	<td><?php echo $this->users[$post['author']];?></td>
	<td>
	<div class="btn-group">
		<a href="<?php 
		echo $this->adminURL('post', 'edit', $post['id']);
		?>" class="btn btn-small btn-primary"><i class="icon-pencil"></i></a>
		<a data-id="<?php echo $post['id']; ?>" href="<?php 
		echo $this->adminURL('post', 'delete', $post['id']);
		?>" class="btn btn-small btn-danger delete"><i class="icon-remove "></i></a>
	</div>
	</td>
</tr>

<?php 
}
	?>
	
</table>
<?php 
	echo $this->paginationControl($this->posts, 'Sliding' , 'pagination.phtml'); 
?>
</div>
</div> <!-- end of .workplace -->

<script type="text/javascript">
$(function (){
	$('.delete').click(function(){
		console.log('Delete clicked');
		if (!confirm ('Bạn có muốn xóa ?')) {
			return false;
		}
		var _dis = this;
		var _id = $(this).attr('data-id');
		$.post('<?php echo $this->baseUrl() ?>/admin/post/delete', {
			id : _id
			},
			function(respone){
				console.log(respone);
				$(_dis).parent().parent().parent().remove();
			}
		);
		
		
		return false;
	});
	$('#cate').change(function (){
	$('#frmSearch').submit();
});
});
</script>